//
//  MainTabBarController.swift
//  groupTasks
//
//  Created by 向银泉 on 16/11/1.
//  Copyright © 2016年 向银泉. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
self.creatcontrollers()
        // Do any additional setup after loading the view.
    }
    func creatcontrollers(){
        
        let healthVC = HealthViewController()
        let myVC = MyViewController()
        let homePageVC = HomePageViewController()
        let musicVC = MusicViewController()
        
        let healthNav = UINavigationController(rootViewController: healthVC)
        let myNav = UINavigationController(rootViewController: myVC)
        let homePageNav = UINavigationController(rootViewController: homePageVC)
        let musicNav = UINavigationController(rootViewController: musicVC)
        
        let vcArray = [homePageVC,musicVC,healthVC,myVC]
        let navArray = [homePageNav,musicNav,healthNav,myNav]
        
        self.viewControllers = navArray
        
        let titleArray = ["资讯","MV","汤之道","我的"]
        let selectImageArray = ["newPress1.png","mvPress","healthPress","myPress"]
        let unselectedImageArray = ["new","mv","health","my"]
        
        
        for i in 0..<vcArray.count{
            let vc = vcArray[i]
            vc.navigationController?.navigationBar.barTintColor = UIColor.blackColor()
            vc.navigationItem.title = titleArray[i]
            vc.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont.systemFontOfSize(20),NSForegroundColorAttributeName:UIColor.whiteColor()]
        }
        for i in 0..<navArray.count{
            let nav = navArray[i]
            nav.tabBarItem.title = titleArray[i]
            nav.tabBarItem.image = UIImage.init(named:unselectedImageArray[i])?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            nav.tabBarItem.selectedImage = UIImage.init(named: selectImageArray[i])?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        }
        let screenW = UIScreen.mainScreen().bounds.width
        let bgview = UIView.init(frame: CGRectMake(0, 0, screenW, 49))
        bgview.backgroundColor = UIColor.init(red: 248/255.0, green: 248/255.0, blue: 248/255.0, alpha: 1)
        self.tabBar.insertSubview(bgview, atIndex: 0)
        
        
        
        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.darkGrayColor(),NSFontAttributeName:UIFont.systemFontOfSize(12)], forState: .Normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.greenColor(),NSFontAttributeName:UIFont.systemFontOfSize(14)], forState: .Selected)
        
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
